package com.misolab.android.post.util.parse.xml;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class XMLParser extends DefaultHandler {

	@Override
	public void startDocument() throws SAXException {
		super.startDocument();
		System.out.println("startDocument()");
	}

	@Override
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		super.startElement(uri, localName, qName, attributes);
		
		System.out.println("	startElement() : " + qName);
		int count = attributes.getLength();
		for (int i = 0; i < count; i++) {
			String key = attributes.getQName(i);
			String value = attributes.getValue(key);
			
			System.out.println(String.format("%d. %s:%s", i, key, value));
		}
	}

	@Override
	public void characters(char[] ch, int start, int length) throws SAXException {
		super.characters(ch, start, length);
		
		System.out.println("		characters() : " + new String(ch, start, length));
	}


	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		super.endElement(uri, localName, qName);
		
		System.out.println("	endElement() : " + qName);

	}

	@Override
	public void endDocument() throws SAXException {
		super.endDocument();
		System.out.println("endDocument()");
	}	
}
